
import requests
import app
import pymysql


class LoginApi(object):
    # 定义初始化方法,可以写进url
    def __init__(self):
        self.get_img_code_url = app.BASE_URL + "/common/public/verifycode1/{}"
        self.session = requests.session
        self.get_sms_code_url = app.BASE_URL + "/member/public/sendSms"
        self.register_url = app.BASE_URL + "/member/public/reg"
        self.login_url = app.BASE_URL + "/member/public/login"
        self.real_name_url = app.BASE_URL + "/member/realname/approverealname"
        self.get_approve_url = app.BASE_URL + "/member/member/getapprove"
        self.get_trust_url = app.BASE_URL + "/trust/trust/register"
        self.get_three_url = "http://mertest.chinapnr.com/muser/publicRequests"
        self.get_verify_url = app.BASE_URL + "/common/public/verifycode/{}"
        self.get_loaninfo_url = app.BASE_URL + "/common/loan/loaninfo"

    # 获取图片验证码接口
    def get_img_code(self,session,r):
        # 准备请求数据
        url = self.get_img_code_url.format(r)
        # 发送请求,接收响应
        response = session.get(url)
        # 返回结果
        return response
    # 获取短信验证码接口
    def get_sms_code(self,session,phone,img_code):
        # 定义获取短信验证码的数据,动态的写进参数,不需要再把获取图片的接口写进来,在执行用例的时候调用就可
        sms_data = {"phone": phone, "imgVerifyCode": img_code, "type": "reg"}
        # 定义获取短信验证码的URL
        url = self.get_sms_code_url
        # 调用session点方法去发送请求
        response = session.post(url,data=sms_data)
        return response
    # 注册的接口
    def register_api(self,session,phone,password,img_code,sms_code,dy_server,invite):
        register_data = {"phone":phone,"password":password,"verifycode":img_code,"phone_code":sms_code,
"dy_server":dy_server,"invite_phone":invite}
        url = self.register_url
        response = session.post(url,register_data)
        return response
    # 登录的接口
    def login_api(self,session,phone,password):
        # 准备请求数据 URL,请求参数
        login_data = {"keywords":phone,"password":password}
        url = self.login_url
        # 发送请求
        response = session.post(url,login_data)
        # 返回响应
        return response
    # 认证的接口
    def real_name_api(self,session,realname,card_id):
        # 准备请求的数据
        app_data = {"real_name":realname,"card_id":card_id}
        # 获取URL,发送请求,返回响应结果
        url = self.real_name_url
        response = session.post(url,data= app_data,files={"x":"y"})
        return response

    # 获取认证信息的接口
    def get_approve_api(self,session):
        url = self.get_approve_url
        response = session.post(url)
        return response
    # 请求开户
    def get_register_trust(self,session):
        url = self.get_trust_url
        response1 = session.post(url)
        return response1
    # 充值验证码接口
    def get_verify_code(self,session,r):
        url = self.get_verify_url.format(r)
        response = session.get(url)
        return response
    # 充值接口
    def recharge_api(self,session,amount,valicode):
        recharge_data = {"paymentType":"chinapnrTrust",
"amount":amount,
"fromStr":"reForm",
"valicode":valicode}
        url = app.BASE_URL + "/trust/trust/recharge"
        response = session.post(url,recharge_data)
        return response










if __name__ == '__main__':
    session = requests.session()
    LoginApi.login_api(session,phone="13012125410", password="test123")
    LoginApi.real_name_api(session,"对对对","360102199003070831")







